package com.ccys.app.controller;

import com.ccys.common.vo.ResponseResultApp;
import com.ccys.db.mapper.TblSupplierMapper;
import com.ccys.db.vo.app.deliveryTimeSlot.GetTimeSlotsV3Vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @Author：XLY
 * @Date：2024/1/26 0026
 */

@RestController
@RequestMapping("/deliveryTimeslotSelectScreen")
@Api(tags = "Delivery Timeslot Select Screen")
public class DeliveryTimeslotSelectScreenController {


    @Resource
    private TblSupplierMapper mapper;

    @ApiOperation("Delivery Timeslot Select Screen/ 1")
    @GetMapping("GetTimeSlotsV3")
    public ResponseResultApp<GetTimeSlotsV3Vo> getTimeSlotsV3(String booking_id) {
        //没管quantity_per_day
        //查询根据dtl_disp_order排序的前六个，如果不够6个就把日期加一天查询补齐6个
        List<GetTimeSlotsV3Vo.TimeSlotVo> today = mapper.getTimeSlotsV3Today();
        int todaySize = today.size();
        if (CollectionUtils.isNotEmpty(today) && todaySize < 6) {
            List<GetTimeSlotsV3Vo.TimeSlotVo> nextDay = mapper.getTimeSlotsV3NextDay();
            int nextDaySize = nextDay.size();
            if (nextDaySize <= 6 - todaySize) {
                today.addAll(nextDay);
            } else {
                today.addAll(nextDay.subList(0, 6 - todaySize));
            }
        }
        GetTimeSlotsV3Vo vo = new GetTimeSlotsV3Vo();
        vo.setTimeSlots(today);
        Integer expressEnable = mapper.getExpressEnable();
        vo.setExpressEnable(Objects.nonNull(expressEnable)&&expressEnable==1);
        return ResponseResultApp.success(vo);
    }

}
